package com.softer.chengxin.corp.service.impl;

import com.softer.chengxin.common.domin.*;
import com.softer.chengxin.common.enums.*;
import com.softer.chengxin.corp.dao.CorpDao;
import com.softer.chengxin.corp.domin.ApproveDTO;
import com.softer.chengxin.corp.domin.Corp;
import com.softer.chengxin.corp.service.CorpService;
import com.softer.chengxin.home.dao.MessageDao;
import com.softer.chengxin.home.domin.Message;
import com.softer.chengxin.person.dao.PersonDao;
import com.softer.chengxin.person.domin.Person;
import com.softer.chengxin.score.util.ScoreUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author Gong Zhiyang
 * @date 2018/10/8
 */
@Service
public class CorpServiceImpl implements CorpService {
    @Autowired
    private CorpDao corpDao;
    @Autowired
    private MessageDao messageDao;
    @Autowired
    private PersonDao personDao;
    @Autowired
    private ScoreUtil scoreUtil;

    /**
     * 获取企业基本信息
     *
     * @param id 企业Id
     * @return 企业信息
     */
    @Override
    public Corp load(Integer id) {
        return corpDao.getCorpInfo(id);
    }

    /**
     * 更改企业状态
     *
     * @param id    企业ID
     * @param state 状态
     * @return 处理结果
     */
    @Override
    public CommonResult updateState(Integer id, int state) {
        //查询企业基本信息
        Corp corpInfo = corpDao.getCorpInfo(id);
        if (StringUtils.isBlank(corpInfo.getLegalPerson())) {
            return new CommonResult(ResultEnum.FAIL.getCode(), "请完善企业基本信息后提交");
        }
        //查询主要人员(1法人代表，2总经理)
        //法人代表
        Person legalPerson = personDao.queryMainPersonnel(id, Common.ONE_MILLION_TEN_THOUSAND_AND_ONE);
        if (legalPerson == null) {
            return new CommonResult(ResultEnum.FAIL.getCode(), "请完善法人代表信息");
        }
        //总经理
        Person generalManager = personDao.queryMainPersonnel(id, Common.ONE_MILLION_TEN_THOUSAND_AND_TWO);
        if (generalManager == null) {
            return new CommonResult(ResultEnum.FAIL.getCode(), "请完善总经理信息");
        }
//        //财务负责人
//        Person financeChief = personDao.queryMainPersonnel(id, String.valueOf(Common.ONE_MILLION_TEN_THOUSAND_AND_THREE));
//        if (financeChief == null) {
//            return new CommonResult(ResultEnum.FAIL.getCode(), "请完善财务负责人信息");
//        }
//        //工程负责人
//        Person projectDirector = personDao.queryMainPersonnel(id, String.valueOf(Common.ONE_MILLION_TEN_THOUSAND_AND_FOUR));
//        if (projectDirector == null) {
//            return new CommonResult(ResultEnum.FAIL.getCode(), "请完善工程负责人信息");
//        }
        String dept = "区";
        if(null != corpInfo && NumberEnum.ZERO.getNum() == corpInfo.getProvinceCompany()){
            state = NumberEnum.FOUR.getNum();
            dept = "市";
        }
        //修改企业状态
        int num = corpDao.updateState(id, state);
        //TODO
        ApproveDTO approveDTO = new ApproveDTO();
        approveDTO.setID(id);
        approveDTO.setYijian(MessageEnum.COMPANY_INFO_SUBMIT.getMsg());
        approveDTO.setState(state);
        //
        corpDao.addCorpOpinion(approveDTO, dept);
        if (num > 0) {
            return new CommonResult(ResultEnum.SUCCESS.getCode(), "企业基本信息提交成功，等待主管部门审核。");
        }
        return new CommonResult(ResultEnum.FAIL.getCode(), "企业基本信息提交审核失败，请稍后再试。");
    }

    /**
     * 保存企业信息
     *
     * @param corp 企业信息
     * @return 处理结果
     */
    @Override
    public CommonResult update(Corp corp) {
        int num = corpDao.updateCorpInfo(corp);
        if (num > 0) {
            return new CommonResult(ResultEnum.SUCCESS.getCode(), "企业基本信息保存成功");
        }
        return new CommonResult(ResultEnum.FAIL.getCode(), "企业基本信息保存失败");
    }

    /**
     * 主管部门，查询企业信息待审批列表
     *
     * @param page      页面实体
     * @param state     状态
     * @param loginName 登陆账号
     * @param name      企业名称
     * @return 结果集
     */
    @Override
    public ManagerPageResult qysb(Page page, String state, String loginName, String name) {
        ManagerPageResult mpr = new ManagerPageResult();
        JsonResult jr = new JsonResult();
        String area = null;
        if (!Common.ADMIN.equals(loginName)) {
            //获取该管理范围内的企业信息
            area = corpDao.getDistinct(loginName);
            if (StringUtils.isEmpty(area)) {
                setResult(mpr, jr);
                return mpr;
            }
        }
        //查询账号是区管理部门还是市管理部门3市   4区
        String code = corpDao.getDicCodeByLoginName(loginName);
        //是否是省内公司(0：否；1：是；)
        String  provinceCompany = null;
        //区
        if( String.valueOf(NumberEnum.FOUR.getNum()).equals(code)){
            provinceCompany = NumberEnum.ONE.getNum()+"";
            //状态（0保存，1提交审核（区审核中），2市审核通过，3审核不通过，4区审核通过（市审核中））
            state = String.valueOf(NumberEnum.ONE.getNum());
        }else if( String.valueOf(NumberEnum.THREE.getNum()).equals(code)){
            provinceCompany = NumberEnum.ZERO.getNum()+"";
            //状态（0保存，1提交审核（区审核中），2市审核通过，3审核不通过，4区审核通过（市审核中））
            state = String.valueOf(NumberEnum.FOUR.getNum());
        }else if("admin".equals(loginName)){
            state = "1,4";
        }
        int num = corpDao.getCorpListNum(area, state, name,provinceCompany);
        if (num <= 0) {
            setResult(mpr, jr);
            return mpr;
        }
        List<Corp> corpList = corpDao.getCorpList(page, area, state, name,provinceCompany);
        jr.setDs(corpList);
        mpr.setCount(num);
        mpr.setJson(jr);
        return mpr;
    }

    private void setResult(ManagerPageResult mpr, JsonResult jr) {
        mpr.setCount(0);
        jr.setDs(new ArrayList());
        mpr.setJson(jr);
    }

    /**
     * 信息提交页面
     *
     * @param id 企业ID
     * @return 信息
     */
    @Override
    public ManagerPageResult querySubmitMsg(Integer id) {
        ManagerPageResult mr = new ManagerPageResult();
        JsonResult jr = new JsonResult();
        List<Map> list = corpDao.querySubmitMsg(id);
        if (list != null) {
            jr.setDs(list);
            mr.setCount(list.size());
            mr.setJson(jr);
            return mr;
        }
        setResult(mr, jr);
        return mr;
    }

    /**
     * 管理员审批企业信息
     *
     * @param approveDTO 审批意见实体
     * @return 处理结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public CommonResult sp(ApproveDTO approveDTO, String loginName) {
        //前台传状态3为审核不通过
        if (NumberEnum.THREE.getNum()==approveDTO.getState()) {
            //修改企业基本信息的状态
            int num = corpDao.updateState(approveDTO.getID(), approveDTO.getState());
            //增加一条审批记录
            corpDao.addCorpOpinion(approveDTO, loginName);
            if (Common.TWO.equals(String.valueOf(approveDTO.getState()))) {
                //审核通过后，修改record表信息
                scoreUtil.updateRecord(approveDTO.getID());
            }
            if (num > Integer.parseInt(Common.ZERO)) {
                //增加通知消息
                addMessage(approveDTO, loginName);
                return new CommonResult(ResultEnum.SUCCESS.getCode(), Common.OPERATE_SUCCESS);
            }
            return new CommonResult(ResultEnum.FAIL.getCode(), Common.OPERATE_FAIL);
        } else {
            int num = 0;
            //查询账号是区管理部门还是市管理部门3市   4区
            String code = corpDao.getDicCodeByLoginName(loginName);
            if (String.valueOf(NumberEnum.FOUR.getNum()).equals(code)) {
                //状态（0保存，1提交审核，2市审核通过，3审核不通过，4区审核通过（市审核中））
                approveDTO.setState(NumberEnum.FOUR.getNum());
                num = corpDao.updateState(approveDTO.getID(), approveDTO.getState());
                //增加一条审批记录
                corpDao.addCorpOpinion(approveDTO, loginName);
                if (Common.TWO.equals(String.valueOf(approveDTO.getState()))) {
                    //审核通过后，修改record表信息
                    scoreUtil.updateRecord(approveDTO.getID());
                }
                if (num > Integer.parseInt(Common.ZERO)) {
                    return new CommonResult(ResultEnum.SUCCESS.getCode(), Common.OPERATE_SUCCESS);
                }
            } else if (String.valueOf(NumberEnum.THREE.getNum()).equals(code) || String.valueOf(NumberEnum.ONE_HUNDRED.getNum()).equals(code)) {
                //状态（0保存，1提交审核，2市审核通过，3审核不通过，4区审核通过（市审核中））
                approveDTO.setState(NumberEnum.TWO.getNum());
                //审批
                num = corpDao.updateState(approveDTO.getID(), approveDTO.getState());
                //增加一条审批记录
                corpDao.addCorpOpinion(approveDTO, loginName);
                if (Common.TWO.equals(String.valueOf(approveDTO.getState()))) {
                    //审核通过后，修改record表信息
                    scoreUtil.updateRecord(approveDTO.getID());
                }
                if (num > Integer.parseInt(Common.ZERO)) {
                    //增加通知消息
                    addMessage(approveDTO, loginName);
                    return new CommonResult(ResultEnum.SUCCESS.getCode(), Common.OPERATE_SUCCESS);
                }
            }
        }
        return new CommonResult(ResultEnum.FAIL.getCode(), Common.OPERATE_FAIL);
    }



    /**
     * 查询企业当前状态
     *
     * @param loginName 登陆账号
     * @return (0保存, 1提交中, 2审核通过, 3审核不通过)
     */
    @Override
    public Integer queryState(String loginName) {
        return corpDao.queryState(loginName);
    }

//    /**
//     * 修改企业record信息
//     *
//     * @param corpId 企业信息
//     */
//    public void updateRecord(Integer corpId) {
//        String year = DateFormatUtil.getSysYear();
//        //得到当前年度该企业的detail信息
//        List<ScoreDetail> scoreDetails = managerDao.getScoreDetails(corpId);
//        //得到该企业当前年度的record表信息
//        ScoreRecord scoreRecord = managerDao.getScoreRecord(corpId, String.valueOf(year));
//        if (scoreRecord != null) {
//            ScoreRecord sr = setScore(scoreDetails, scoreRecord, corpId, year);
//            managerDao.updateScoreRecord(sr);
//        } else {
//            ScoreRecord sr = setScore(scoreDetails, new ScoreRecord(), corpId, year);
//            managerDao.insertScoreRecord(sr);
//        }
//    }
//
//    public ScoreRecord setScore(List<ScoreDetail> scoreDetails, ScoreRecord scoreRecord, Integer corpId, String year) {
//        //重新计算该企业各项得分
//        BigDecimal b = new BigDecimal(0);
//        BigDecimal jc01 = new BigDecimal(60);
//        BigDecimal jc02 = new BigDecimal(0);
//        BigDecimal jc03 = new BigDecimal(0);
//        BigDecimal jc04 = new BigDecimal(0);
//        BigDecimal jc05 = new BigDecimal(0);
//        BigDecimal jc06 = new BigDecimal(0);
//        BigDecimal jc07 = new BigDecimal(0);
//        BigDecimal yl01 = new BigDecimal(0);
//        BigDecimal yl02 = new BigDecimal(0);
//        BigDecimal yl03 = new BigDecimal(0);
//        BigDecimal yl04 = new BigDecimal(0);
//        BigDecimal yl05 = new BigDecimal(0);
//        BigDecimal yl06 = new BigDecimal(0);
//        BigDecimal yl07 = new BigDecimal(0);
//        BigDecimal yl08 = new BigDecimal(0);
//        BigDecimal fm01 = new BigDecimal(0);
//        BigDecimal fm02 = new BigDecimal(0);
//        BigDecimal fm03 = new BigDecimal(0);
//        BigDecimal fm04 = new BigDecimal(0);
//        BigDecimal fm05 = new BigDecimal(0);
//        BigDecimal fm06 = new BigDecimal(0);
//        BigDecimal fm07 = new BigDecimal(0);
//        scoreRecord.setYl01(b);
//        scoreRecord.setYl02(b);
//        scoreRecord.setYl03(b);
//        scoreRecord.setYl04(b);
//        scoreRecord.setYl05(b);
//        scoreRecord.setYl06(b);
//        scoreRecord.setYl07(b);
//        scoreRecord.setYl08(b);
//        scoreRecord.setFm01(b);
//        scoreRecord.setFm02(b);
//        scoreRecord.setFm03(b);
//        scoreRecord.setFm04(b);
//        scoreRecord.setFm05(b);
//        scoreRecord.setFm06(b);
//        scoreRecord.setFm07(b);
//        for (ScoreDetail scoreDetail : scoreDetails) {
//            if (scoreDetail.getScore() != null) {
//                switch (scoreDetail.getScoreTypeId()) {
//                    case 1:
//                        yl01 = yl01.add(scoreDetail.getScore());
//                        if (yl01.compareTo(MaxScoreEnum.SIX.getScore()) >= 0) {
//                            yl01 = MaxScoreEnum.SIX.getScore();
//                        }
//                        scoreRecord.setYl01(yl01);
//                        break;
//                    case 2:
//                        yl02 = yl02.add(scoreDetail.getScore());
//                        if (yl02.compareTo(MaxScoreEnum.TEN.getScore()) >= 0) {
//                            yl02 = MaxScoreEnum.TEN.getScore();
//                        }
//                        scoreRecord.setYl02(yl02);
//                        break;
//                    case 3:
//                        yl03 = yl03.add(scoreDetail.getScore());
//                        if (yl03.compareTo(MaxScoreEnum.FORE.getScore()) >= 0) {
//                            yl03 = MaxScoreEnum.FORE.getScore();
//                        }
//                        scoreRecord.setYl03(yl03);
//                        break;
//                    case 4:
//                        yl04 = yl04.add(scoreDetail.getScore());
//                        if (yl04.compareTo(MaxScoreEnum.FORE.getScore()) >= 0) {
//                            yl04 = MaxScoreEnum.FORE.getScore();
//                        }
//                        scoreRecord.setYl04(yl04);
//                        break;
//                    case 5:
//                        yl05 = yl05.add(scoreDetail.getScore());
//                        if (yl05.compareTo(MaxScoreEnum.FORE.getScore()) >= 0) {
//                            yl05 = MaxScoreEnum.FORE.getScore();
//                        }
//                        scoreRecord.setYl05(yl05);
//                        break;
//                    case 6:
//                        yl06 = yl06.add(scoreDetail.getScore());
//                        if (yl06.compareTo(MaxScoreEnum.FORE.getScore()) >= 0) {
//                            yl06 = MaxScoreEnum.FORE.getScore();
//                        }
//                        scoreRecord.setYl06(yl06);
//                        break;
//                    case 7:
//                        yl07 = yl07.add(scoreDetail.getScore());
//                        if (yl07.compareTo(MaxScoreEnum.FORE.getScore()) >= 0) {
//                            yl07 = MaxScoreEnum.FORE.getScore();
//                        }
//                        scoreRecord.setYl07(yl07);
//                        break;
//                    case 8:
//                        yl08 = yl08.add(scoreDetail.getScore());
//                        if (yl08.compareTo(MaxScoreEnum.FORE.getScore()) >= 0) {
//                            yl08 = MaxScoreEnum.FORE.getScore();
//                        }
//                        scoreRecord.setYl08(yl08);
//                        break;
//                    case 9:
//                        fm01 = fm01.add(scoreDetail.getScore());
//                        if (fm01.compareTo(MaxScoreEnum.SIX.getScore()) >= 0) {
//                            fm01 = MaxScoreEnum.SIX.getScore();
//                        }
//                        scoreRecord.setFm01(fm01);
//                        break;
//                    case 10:
//                        fm02 = fm02.add(scoreDetail.getScore());
//                        if (fm02.compareTo(MaxScoreEnum.SIX.getScore()) >= 0) {
//                            fm02 = MaxScoreEnum.SIX.getScore();
//                        }
//                        scoreRecord.setFm02(fm02);
//                        break;
//                    case 11:
//                        fm03 = fm03.add(scoreDetail.getScore());
//                        if (fm03.compareTo(MaxScoreEnum.THREE.getScore()) >= 0) {
//                            fm03 = MaxScoreEnum.THREE.getScore();
//                        }
//                        scoreRecord.setFm03(fm03);
//                        break;
//                    case 12:
//                        fm04 = fm04.add(scoreDetail.getScore());
//                        if (fm04.compareTo(MaxScoreEnum.FIVE.getScore()) >= 0) {
//                            fm04 = MaxScoreEnum.FIVE.getScore();
//                        }
//                        scoreRecord.setFm04(fm04);
//                        break;
//                    case 13:
//                        fm05 = fm05.add(scoreDetail.getScore());
//                        if (fm05.compareTo(MaxScoreEnum.FIVE.getScore()) >= 0) {
//                            fm05 = MaxScoreEnum.FIVE.getScore();
//                        }
//                        scoreRecord.setFm05(fm05);
//                        break;
//                    case 14:
//                        fm06 = fm06.add(scoreDetail.getScore());
//                        if (fm06.compareTo(MaxScoreEnum.FIVE.getScore()) >= 0) {
//                            fm06 = MaxScoreEnum.FIVE.getScore();
//                        }
//                        scoreRecord.setFm06(fm06);
//                        break;
//                    case 15:
//                        fm07 = fm07.add(scoreDetail.getScore());
//                        if (fm07.compareTo(MaxScoreEnum.FIVE.getScore()) >= 0) {
//                            fm07 = MaxScoreEnum.FIVE.getScore();
//                        }
//                        scoreRecord.setFm07(fm07);
//                        break;
//                    default:
//                        break;
//                }
//            }
//        }
///**
// * TODO 基础分数计算方式，当前模式：给满分60
// */
////------------------------------基础算分开始------------------------------------------------
////        //jc_02 企业固定员工人数
////        int personCount = corpDao.findCountPerson(corpId);
////        if (personCount < Common.HUNDRED) {
////            jc02 = new BigDecimal(Figure.HALF);
////        } else if (personCount >= Common.HUNDRED && personCount < Common.THREE_HUNDRED) {
////            jc02 = new BigDecimal(Figure.ONE);
////        } else if (personCount >= Common.THREE_HUNDRED) {
////            jc02 = new BigDecimal(Figure.TWO);
////        }
////        //jc_03
////        // 企业管理技术人员
////        //企业中级职称以上人数
////        int managerCount = corpDao.findCountManagerPerson(corpId);
////        if (managerCount >= Common.FIVE && managerCount < Common.TEN) {
////            jc03 = new BigDecimal(Figure.TWO);
////        } else if (managerCount >= Common.TEN && managerCount < Common.FIFTEEN) {
////            jc03 = new BigDecimal(Figure.THREE);
////        } else if (managerCount >= Common.FIFTEEN) {
////            jc03 = new BigDecimal(Figure.FOUR);
////        }
////        //jc_04
////        // 企业员工专业素质情况
////        //企业的项目负责人人数
////        Integer proManager = corpDao.getCountProManagerPerson(corpId);
////        //企业的项目负责人参加培训的人数
////        Integer proTrainManager = corpDao.getCountProManagerPersonTrain(corpId, year);
////        if (proManager != 0 && proTrainManager != 0) {
////            double ret = proTrainManager / proManager;
////            if (ret < 0.6) {
////                jc04 = new BigDecimal(Figure.ZERO);
////            } else if (ret >= 0.6 && ret < 0.8) {
////                jc04 = new BigDecimal(Figure.ONE);
////            } else if (ret >= 0.8) {
////                jc04 = new BigDecimal(Figure.TWO);
////            }
////        }
////        //企业的其他人员惨参加培训的人数
////        Integer proTrain = corpDao.getCountProPersonTrain(corpId, year);
////        BigDecimal proTrainBD = new BigDecimal(0);
////        if (proManager != 0 && proTrain != 0) {
////            double ret = proTrainManager / proTrain;
////            if (ret < 0.6) {
////                proTrainBD = new BigDecimal(Figure.ZERO);
////            } else if (ret >= 0.6 && ret < 0.8) {
////                proTrainBD = new BigDecimal(Figure.ONE);
////            } else if (ret >= 0.8) {
////                proTrainBD = new BigDecimal(Figure.TWO);
////            }
////        }
////        jc04 = jc04.add(proTrainBD);
////
////        //jc_05
////        // 企业经营情况
////        CorpVO corpVO = corpDao.getCorpOperate(corpId);
////        BigDecimal contract = new BigDecimal(0);
////        //其他经营年限
////        if (corpVO.getYear() == null) {
////            jc05 = new BigDecimal(Figure.ZERO);
////        } else {
////            Calendar calendar = Calendar.getInstance();
////            int nowYear = calendar.get(Calendar.YEAR);
////            int jisuan = nowYear - corpVO.getYear();
////            if (jisuan < 2) {
////                jc05 = new BigDecimal(Figure.ZERO);
////            } else if (jisuan >= 2 && jisuan < 4) {
////                jc05 = new BigDecimal(Figure.ONE);
////            } else if (jisuan >= 4 && jisuan < 6) {
////                jc05 = new BigDecimal(Figure.TWO);
////            } else if (jisuan >= 6) {
////                jc05 = new BigDecimal(Figure.THREE);
////            }
////            if (StringUtils.isNotBlank(corpVO.getCreditContractPath())) {
////                //是否是重合同守信用企业
////                contract = new BigDecimal(Figure.ONE);
////            }
////        }
////        jc05 = jc05.add(contract);
////        //jc_06
////        // 物业管理面积
////        Integer area = corpDao.getCorpArea(corpId);
////        if (area != null) {
////            if (area >= 30 && area < 60) {
////                jc06 = new BigDecimal(Figure.ONE);
////            } else if (area >= 60 && area < 90) {
////                jc06 = new BigDecimal(Figure.TWO);
////            } else if (area >= 90 && area < 120) {
////                jc06 = new BigDecimal(Figure.THREE);
////            } else if (area >= 120) {
////                jc06 = new BigDecimal(Figure.FOUR);
////            } else {
////                jc06 = new BigDecimal(Figure.ZERO);
////            }
////        } else {
////            jc06 = new BigDecimal(Figure.ZERO);
////        }
////        //jc_07
////        // 参与保障性住房、老旧小区等物业服务
////        Integer baozhang = corpDao.getCorpBZArea(corpId);
////        if (baozhang != null) {
////            if (baozhang >= Common.FIVE && baozhang < Common.TEN) {
////                jc07 = new BigDecimal(Figure.ONE);
////            } else if (baozhang >= Common.TEN) {
////                jc07 = new BigDecimal(Figure.TWO);
////            } else {
////                jc07 = new BigDecimal(Figure.ZERO);
////            }
////        } else {
////            jc07 = new BigDecimal(Figure.ZERO);
////        }
////        scoreRecord.setJc01(jc01);
////        scoreRecord.setJc02(jc02);
////        scoreRecord.setJc03(jc03);
////        scoreRecord.setJc04(jc04);
////        scoreRecord.setJc05(jc05);
////        scoreRecord.setJc06(jc06);
////        scoreRecord.setJc07(jc07);
////------------------------------基础算分结束------------------------------------------------
//        scoreRecord.setJc01(jc01);
//        scoreRecord.setJc02(jc02);
//        scoreRecord.setJc03(jc03);
//        scoreRecord.setJc04(jc04);
//        scoreRecord.setJc05(jc05);
//        scoreRecord.setJc06(jc06);
//        scoreRecord.setJc07(jc07);
//        //计算总得分
//        BigDecimal allScore = countScore(scoreRecord);
//        String dj = sdManagerService.getLevel(allScore);
//        scoreRecord.setAllScore(allScore);
//        scoreRecord.setDj(dj);
//        scoreRecord.setGmtModified(new Date());
//        scoreRecord.setPoguid(corpId);
//        scoreRecord.setYear(year);
//        return scoreRecord;
//    }
//
//    /**
//     * 计算总分
//     */
//    private BigDecimal countScore(ScoreRecord scoreRecord) {
//        BigDecimal jcScore = scoreRecord.getJc01().add(scoreRecord.getJc02()).
//                add(scoreRecord.getJc03()).add(scoreRecord.getJc04()).
//                add(scoreRecord.getJc05()).add(scoreRecord.getJc06()).
//                add(scoreRecord.getJc07());
//        BigDecimal fmScore = scoreRecord.getFm01().add(scoreRecord.getFm02()).
//                add(scoreRecord.getFm03()).add(scoreRecord.getFm04()).
//                add(scoreRecord.getFm05()).add(scoreRecord.getFm06()).
//                add(scoreRecord.getFm07());
//        BigDecimal ylScore = scoreRecord.getYl01().add(scoreRecord.getYl02()).
//                add(scoreRecord.getYl03()).add(scoreRecord.getYl04()).
//                add(scoreRecord.getYl05()).add(scoreRecord.getYl06()).
//                add(scoreRecord.getYl07()).add(scoreRecord.getYl08());
//
//        BigDecimal allScore = jcScore.add(ylScore).subtract(fmScore);
//        return allScore;
//    }

    /**
     * 新增通知消息
     *
     * @param approveDTO 审批实体
     * @param loginName  登陆用户
     */
    public void addMessage(ApproveDTO approveDTO, String loginName) {
        Message message = new Message();
        message.setAdder(loginName);
        message.setCropid(approveDTO.getID());
        //企业信息的消息类型定义为0
        message.setType(Integer.parseInt(Common.ZERO));
        message.setUrl(UrlEnum.COMPANY_INFO.getUrl());

        if (approveDTO.getState() == StateEnum.PASS_THROUGH.getCode()) {
            message.setTitle(MessageEnum.COMPANY_INFO_THROUGH.getMsg());
        } else {
            message.setTitle(MessageEnum.COMPANY_INFO_NO_THROUGH.getMsg());
        }
        messageDao.addMessage(message);
    }
}
